n = int(input())
m = []
for i in range(n):
m.append(input())
l = m[0][0]
other = m[0][1]
for i in range((n//2)):
if m[i][i] != l or m[i][n-1-i] != l or m[n-1-i][i] != l or m[n-1-i][n-1-i] != l:
print("NO")
exit()
if m[((n+1)//2)-1][((n+1)//2)-1] == l and m[((n+1)//2)-1].count(l) == 1:
for i in range(n):
for j in range(n):
if m[i].count(l) > 2 or m[i][j] != other and m[i][j] != l or len(set(m[i])) == 1:
print("NO")
exit()
print("YES")
exit()
print("NO")
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;
long long w1,w2,w3,n,k,l,i,j,a,mn,x,b,mx,ans,sum,s5,s1,s2,s3,s4,ch1,ch2,r,so,flag,g,num,f;
pair < ll,ll > pr[100001],rp[100001];
string sd[400],sf,m1,m2,sg;
stringstream ss;
char c1,c2,c3,c4,c;
int main()
{
mx=1e9;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
cin >> n;
for(i=0;i<n;i++)
{
cin >> sd[i];
}
c1=sd[0][0];
c2=sd[0][1];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(sd[i][j]==c1)
{
s1++;
}
}
if(s1>2 or (i==n/2 and s1>=2))
{
cout << "NO" << endl;
return 0;
}
s1=0;
if(sd[i][i]!=c1 or sd[i][i+1]==c1)
{
cout << "NO" << endl;
return 0;
}
if(sd[i][n-i-1]!=c1 or sd[i][n-i-2]==c1)
{
cout << "NO" << endl;
return 0;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(sd[i][j]!=c1 and sd[i][j]!=c2)
{
cout << "NO" << endl;
return 0;
}
}
}
cout << "YES" << endl;
return 0;
}
/*
48
57
*/
1712D - Empty Graph | 1712B - Woeful Permutation |
1712C - Sort Zero | 1028B - Unnatural Conditions |
735B - Urbanization | 746C - Tram |
1278B - A and B | 1353D - Constructing the Array |
1269C - Long Beautiful Integer | 1076A - Minimizing the String |
913C - Party Lemonade | 1313A - Fast Food Restaurant |
681A - A Good Contest | 1585F - Non-equal Neighbours |
747A - Display Size | 285A - Slightly Decreasing Permutations |
515C - Drazil and Factorial | 1151E - Number of Components |
1151F - Sonya and Informatics | 556A - Case of the Zeros and Ones |
867A - Between the Offices | 1569A - Balanced Substring |
260A - Adding Digits | 1698C - 3SUM Closure |
1029B - Creating the Contest | 1421A - XORwice |
1029A - Many Equal Substrings | 1675D - Vertical Paths |
1271C - Shawarma Tent | 805A - Fake NP |